package com.hz.ruoyilgorder.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hz.rouyigonggong.domain.LgDeliveryInfo;
import com.hz.rouyigonggong.domain.dto.LgDeliveryInfoDTO;
import com.hz.rouyigonggong.domain.dto.LgDriverLogisticsDTO;
import com.hz.ruoyilgorder.mapper.LgDeliveryInfoDTOMapper;
import com.hz.ruoyilgorder.mapper.LgDeliveryInfoMapper;
import com.hz.ruoyilgorder.service.LgDeliveryInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @version 1.0
 * @Author yzw
 * @Date 2025/3/10 11:01
 * @注释
 */
@Service
public class LgDeliveryInfoServiceImpl extends ServiceImpl<LgDeliveryInfoMapper, LgDeliveryInfo> implements LgDeliveryInfoService {
   @Autowired
   private LgDeliveryInfoMapper  lgDeliveryInfoMapper;

   @Autowired
   private LgDeliveryInfoDTOMapper lgDeliveryInfoDTOMapper;


    @Override
    public List<LgDeliveryInfoDTO> getList(LgDeliveryInfoDTO lgDeliveryInfoDTO) {
        return lgDeliveryInfoDTOMapper.getList(lgDeliveryInfoDTO);
    }

    @Override
    public int add(LgDeliveryInfoDTO dto) {


        if(lgDeliveryInfoDTOMapper.getorder(dto.getOrderNumber())==null ){
            //新增
            return lgDeliveryInfoDTOMapper.insert(dto);
        }
        if (lgDeliveryInfoDTOMapper.getorder(dto.getOrderNumber())!=null){
            //修改
            UpdateWrapper<LgDeliveryInfoDTO> updateWrapper = new UpdateWrapper<>();
            updateWrapper.eq("order_number",dto.getOrderNumber());
            return  lgDeliveryInfoDTOMapper.update(dto, updateWrapper);
        }
        return  0;
    }

    @Override
    public int adddriver(LgDeliveryInfoDTO dto) {
        //判断是否已经有了车辆
        if( lgDeliveryInfoDTOMapper.getorder(dto.getOrderNumber())==null){
            //新增数据
            return lgDeliveryInfoDTOMapper.insert(dto);
        }
        //判断是否已经有了司机
        if( lgDeliveryInfoDTOMapper.getorder(dto.getOrderNumber())!=null){
            //修改
            UpdateWrapper<LgDeliveryInfoDTO> updateWrapper = new UpdateWrapper<>();
            updateWrapper.eq("order_number",dto.getOrderNumber());
            return  lgDeliveryInfoDTOMapper.update(dto, updateWrapper);
        }

        return 0;
    }

    @Override
    public LgDeliveryInfoDTO getInfo(Integer id) {
        return lgDeliveryInfoDTOMapper.getInfo(id);
    }

    @Override
    public List<LgDeliveryInfoDTO> getoutcold(Integer driverId) {
        return lgDeliveryInfoDTOMapper.getoutcold(driverId);
    }
}
